import React, { Component } from 'react'
import ReactDOM from 'react-dom';
import { Modal, Form, message } from 'antd';
import {fetchData} from '../../../components/AjaxConsumer'
import AddForm from './AddForm'

const confirm = Modal.confirm;

export default class AddPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            formTitle: '',
            visible: false,
            resData: {},
            submitUrl: '/base/team/c'
        };
    }

    //显示弹框
    showModal = () => {
        this.setState({
            visible: true,
        });
    }
    // 隐藏弹出框
    hideModal = () => {
        this.setState({
            visible: false,
        });
    }
    // 新增班组
    addWorkareaHandle = () => {
        this.setState(
            {
                submitUrl: '/base/team/c',
                formTitle: '新增班组',
                isEdit: false,
                resData: {}
            }
        );
        console.log("====11111111111111====");
        this.showModal();//显示弹框
    }

    // editGetInfoCallBack = (resData)=> {
    //     console.log("修改数据：\n",JSON.stringify(resData, null, 4));
    //     this.setState(
    //         {
    //             submitUrl: '/material/intowarehouse/barcode/edit',
    //             resData: resData.data,
    //             isEdit: true,
    //             formTitle: '修改条码'
    //         }
    //     );
    //     this.showModal();//显示弹框
    // }

    // // 编辑信息
    // editHandle = (rowObj) => {
    //     this.setState({resData: {}});
    //     //根据对象的Id 属性获取对象信息
    //     let id = rowObj.id;
    //     const options = {
    //         url: '/material/intowarehouse/barcode/get/' + id,
    //         type: 'get',//请求方式
    //         condition: {id: id}
    //     };
    //     console.log("====222222222222====");
    //     fetchData(this, options, this.editGetInfoCallBack);
    // }
    // // 删除后的回调
    // deleteCallBackHandle = (resData)=> {
    //     let result = resData;
    //     //alert("提交返回数据：\n",JSON.stringify(result, null, 4));
    //     if (result.code == '1') {
    //         message.success('删除成功！');
    //         this.refreshHandle();
    //     } else {
    //         message.info(result.msg);
    //     }
    // }

    // // 删除工作区
    // deleteHandle = (rowObj) => {
    //     let id = rowObj.id;
    //     // let userIdArr = [];
    //     // userIdArr.push(userId);
    //     const options = {
    //         url: '/material/intowarehouse/barcode/d',
    //         condition: {id: id}
    //     };
    //     let _that = this;
    //     confirm({
    //         title: '您确定要删除吗？',
    //         onOk() {
    //             fetchData(_that, options, _that.deleteCallBackHandle);
    //             console.log("------------删除操作------------------")
    //         },
    //         onCancel() {
    //             console.log("取消了删除操作")
    //         },
    //     });
    // }

    // 新增/修改后的回调
    handleOk = () => {
        this.hideModal();
        this.refreshHandle();
    }

    handleCancel = () => {
        //表单重置
        this.refs.modalFrom.resetFields();
        this.hideModal();
    }

    //刷新List列表
    refreshHandle = () => {
        console.log("刷新List列表")
        this.props.refreshHandle();
    }

    render() {
        if (this.state.resData != null && this.state.resData.data != null) {
            let factory = this.state.resData.data;
            this.getFormData.map((e, index) => {
                e.initialValue = factory[e.name]
            });
        }

        return (
            <Modal
                style={{top:'20px'}}
                visible={this.state.visible}
                title={this.state.formTitle ? this.state.formTitle : '填写表单'}
                onOk={this.handleOk}
                onCancel={this.handleCancel}
                width={this.formAlerSize=='large'?'850px':'400px'}
                footer=''
            >

                <AddForm
                    ref="modalFrom"
                    isEdit={this.state.isEdit}
                    submitUrl={this.state.submitUrl}
                    onCancel={this.handleCancel}
                    factoryCode="all"
                    formData={this.state.resData}
                    refreshHandle={this.refreshHandle}
                />

            </Modal>
        )
    }
}